package com.marketingManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.pojo.TbAdvertise;
import com.eight.pojo.TbUser;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.marketingManagement.dao.advertiseMapper;
import com.marketingManagement.service.advertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author caoch
 * @since 2023/2/28 19:48
 **/
@Service
public class advertiseServiceImpl extends ServiceImpl<advertiseMapper, TbAdvertise> implements advertiseService {
	@Autowired
	private advertiseMapper advertiseMapper;

	/**
	 * 添加广告
	 * @param advertise
	 * @return int
	 */
	public int addAdvertise(TbAdvertise advertise){
		return advertiseMapper.insert(advertise);
	}

	/**
	 * 修改广告
	 * @param advertise
	 * @return
	 */
	public int updateAdvertise(TbAdvertise advertise){
		QueryWrapper<TbAdvertise> wrapper = new QueryWrapper<>();
		wrapper.eq("id",advertise.getId());
		return advertiseMapper.update(advertise,wrapper);
	}

	/**
	 *删除操作
	 * @param id
	 * @return
	 */
	public int removeAdvertise(int id){
		return advertiseMapper.deleteById(id);
	}

	/**
	 * 广告查询
	 * @param currentPage
	 * @param pageSize
	 * @param advertise
	 * @return
	 */
	public PageInfo<TbAdvertise> selectAdvertise(Integer currentPage, Integer pageSize, TbAdvertise advertise){
		PageHelper.startPage(currentPage,pageSize);
		QueryWrapper<TbAdvertise> wrapper = new QueryWrapper<>();
		wrapper.like(advertise.getName()!=null,"name",advertise.getName());
		List<TbAdvertise> tbAdvertises = advertiseMapper.selectList(wrapper);
		PageInfo<TbAdvertise> tbAdvertisePageInfo = new PageInfo<>(tbAdvertises);
		return tbAdvertisePageInfo;
	}

	/**
	 * 轮播广告头部
	 * @param number
	 * @return
	 */
	@Override
	public List<TbAdvertise> getAdvertise(int number) {
		return advertiseMapper.getAdvertise(number);
	}

	/**
	 * 轮播广告个数 头
	 * @return
	 */
	@Override
	public int getHeadNum() {
		return advertiseMapper.getHeadNum();
	}

	/**
	 * 首页中部图
	 * @param number
	 * @return
	 */
	@Override
	public List<TbAdvertise> getCentral(int number) {
		System.out.println(number+"service++++++++++++++++++++++++++++");
		return advertiseMapper.getCentral(number);
	}
	/**
	 * 轮播广告个数 中
	 * @return
	 */
	@Override
	public int getCentralNum() {
		return advertiseMapper.getCentralNum();
	}

	/**
	 * 根据登录用户名查询用户ID
	 *
	 * @param username
	 * @return
	 */
	@Override
	public TbUser getUserInfo(String username) {
		return advertiseMapper.getUserInfo(username);
	}
}
